//
//  ReferViewController.m
//  Koala_Fm
//
//  Created by dllo on 16/1/19.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ReferViewController.h"
#import "AFNetBlock.h"
#import <UIImageView+WebCache.h>
#import "ListendataHandler.h"
#import "ReferTableViewCell.h"
#import "PictureModel.h"
#import "DetaLisViewController.h"
@interface ReferViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *dataArr;
@property(nonatomic, retain)NSIndexPath *index;
@end

@implementation ReferViewController
- (void)dealloc
{
    [_tableView release];
    [_dataArr release];
    [super dealloc];
}
// 视图初始化
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 30 - 49)style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        // 重用池
        [_tableView registerClass:[ReferTableViewCell class] forCellReuseIdentifier:@"cell"];
        [_tableView release];
     }
    return self;
}





- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
}
#pragma mark - 数据请求
-(UITableView *)tableViewSetWithUrlString:(NSString *)urlStr{
    [AFNetBlock GetDataWithURL:urlStr block:^(id block) {
        self.dataArr = block[@"result"][@"dataList"];
//        NSLog(@"%@", _dataArr);
        [_tableView reloadData];
    }];
    return _tableView;
}

#pragma mark - 设置cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ReferTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    [cell.imag sd_setImageWithURL:[NSURL URLWithString:_dataArr[indexPath.row][@"pic"]]];
    cell.imagOne.image =[UIImage imageNamed:@"jiahao"];
    cell.imagTow.image =[UIImage imageNamed:@"erji"];
    cell.titleLable.text = _dataArr[indexPath.row][@"name"];
    cell.contentLable.text = _dataArr[indexPath.row]
    [@"desc"];
    
   
     // 判断数字是否超一万
    if ([_dataArr[indexPath.row][@"followedNum"] floatValue] > 10000) {
        
        NSString *str = [NSString stringWithFormat:@"%.1f万次订阅",[_dataArr[indexPath.row][@"followedNum"] floatValue] / 10000];
        cell.subscribeLable.text = str;
    }else{
        NSString *ster = [NSString stringWithFormat:@"%.1f次订阅",[_dataArr[indexPath.row][@"followedNum"] floatValue]];
        cell.subscribeLable.text = ster;
    }
    if ([_dataArr[indexPath.row][@"listenNum"]floatValue] > 10000) {
        NSString *strr = [NSString stringWithFormat:@"%.1f万次收听",[_dataArr[indexPath.row][@"listenNum"]floatValue] / 10000];
        cell.listenLable.text = strr;
        
}

    return cell;
}
#pragma mark - 设置cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
    
// 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// 取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *strry = [NSString stringWithFormat:@"%@",_dataArr[indexPath.row][@"id"] ];
    NSString *name = [NSString stringWithFormat:@"%@",_dataArr[indexPath.row][@"name"] ];
     NSString *iamge = [NSString  stringWithFormat:@"%@",_dataArr[indexPath.row][@"pic"] ];
    
      [self.delegate pass:strry name:name iamge:iamge];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
